﻿/* 事件集合 */
//起始点参数


//结束点参数
var ISS_MAP_SEARCH_END_NAV = {
    Lng: "",
    Lat: "",
    Name: "终点"
};

//返回按钮
$("#returnbox").click(function () {
    window.location.href = _home;
}); 

//搜索框enter
$(".searchbar-input input").keydown(function (key) {
    ISS_MAP.Markers = []; //清空marker
    if (key.keyCode == 13) {
        ISS_MAP.Keyword = $(".searchbar-input input")[0].value;
        if (ISS_MAP.sroll.current_tabindex == 0) {
            $$("#tab_Ticket .content-block").html("");
            $$('.infinite-scroll-preloaderTicket').show();
            LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab0, ISS_MAP.sroll.current_tabindex);
        } else if (ISS_MAP.sroll.current_tabindex == 1) {
            $$("#tab_Hotel .content-block").html("");
            $$('.infinite-scroll-preloaderHotel').show();
            LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab1, ISS_MAP.sroll.current_tabindex);
        } else if (ISS_MAP.sroll.current_tabindex == 2) {
            $$("#tab_Rest .content-block").html("");
            $$('.infinite-scroll-preloaderRest').show();
            LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab2, ISS_MAP.sroll.current_tabindex);
        }
    }
});
$(".searchbar-input input").change(function (key) {
    ISS_MAP.Keyword = $(".searchbar-input input")[0].value;
});
////文本框输入事件改变语音按钮位置
///* 键盘输入弹起 */
//$(".searchbar-input input").keyup(function () {
//    if ($(".searchbar-input input").val() != "") {
//        $(".voicediv").css("margin-left", "-52px");
//    } else {
//        $(".voicediv").css("margin-left", "-32px");
//    }
//});
///* 清空 */
//$(".searchbar-input a").click(function () {
//    $(".voicediv").css("margin-left", "-32px");
//});
///* 取消 */
//$(".searchbar-cancel").click(function () {
//    $(".voicediv").css("margin-left", "-32px");
//});

/***********    地图使用公共方法    **********/
//地图跳转-类似周边，跳转景区，要iframe能使用
function MapClickJump(url, param) {
    mainView.router.loadPage({ url: url, reload: false });
}
//调用语音接口，返回给子界面--地图使用
var voice = {
    localId: '',
    serverId: ''
};
function ReturnStartVoice() {
    wx.startRecord({
        cancel: function () {
            alert('用户拒绝授权录音');
        }
    });
};
function ReturnEndVoid(callback) {
    wx.stopRecord({
        success: function (res) {
            voice.localId = res.localId;
            wx.translateVoice({
                localId: voice.localId, // 需要识别的音频的本地Id，由录音相关接口获得
                isShowProgressTips: 1, // 默认为1，显示进度提示
                success: function (res) {
                    if (res.translateResult != 'undefined' && res.translateResult != '') {
                        yy = res.translateResult.replace(/['",.!?，。？！]/ig, ""); // 语音识别的结果
                        callback(yy);
                    }
                }
            });
        },
        fail: function (res) {
            alert(JSON.stringify(res));
        }
    });
};
//语音按钮事件
/* 初始化语音config */
var gn = ['startRecord', 'stopRecord', 'translateVoice', 'openLocation', 'getLocation'];
wx_config(gn, function () {
    //callback 所有JSSDK事件
}, function () {
    //errorcallback  config注册失败事件
});
/***********    地图使用公共方法----结束    **********/

/* 开始录音 */
$(".searchimg").click(function () {
    myApp.popup('.popup-about');
    wx.startRecord({
        cancel: function () {
            myApp.alert("用户拒绝授权录音");
        }
    });
});
/* 结束录音 */
$$('.close-popup').on('click', function () {
    myApp.closeModal('.popup-about');
    wx.stopRecord({
        success: function (res) {
            voice.localId = res.localId;
            wx.translateVoice({
                localId: voice.localId, // 需要识别的音频的本地Id，由录音相关接口获得
                isShowProgressTips: 1, // 默认为1，显示进度提示
                success: function (res) {
                    if (res.translateResult != 'undefined' && res.translateResult != '') {
                        yy = res.translateResult.replace(/['",.!?，。？！]/ig, ""); // 语音识别的结果
                        $(".searchbar-input input")[0].value = yy;
                        ISS_MAP.Keyword = yy;
                        //查询
                        if (ISS_MAP.sroll.current_tabindex == 0) {
                            ISS_MAP.sroll.index_tab0 = 1;
                            LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab0, ISS_MAP.sroll.current_tabindex);
                        } else if (ISS_MAP.sroll.current_tabindex == 1) {
                            ISS_MAP.sroll.index_tab1 = 1;
                            LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab1, ISS_MAP.sroll.current_tabindex);
                        } else if (ISS_MAP.sroll.current_tabindex == 2) {
                            ISS_MAP.sroll.index_tab2 = 1;
                            LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab2, ISS_MAP.sroll.current_tabindex);
                        }
                    }
                }
            });
        },
        fail: function (res) {
            alert(JSON.stringify(res));
        }
    });
});

//拖动清单事件
//ISS_MAP_Resize($("#dragbar")[0], $("#pickbar")[0]);
var pickheight = true;
$("#dragbar").click(function () {
    if (pickheight) {
        $("#pickbar")[0].style.height = "20px";
        $("#map-box")[0].style.height = "calc(100% - 20px)";
        pickheight = false;
    } else {
        $("#pickbar")[0].style.height = "42%";
        $("#map-box")[0].style.height = "58%";
        pickheight = true;
    }
});

//切换tab事件
$$(".buttons-tabs-D a").click(function () {
    //置顶
    $$('.infinite-scroll').scrollTop(0);
    //标识当前tab  0:门票 1:酒店 2:餐厅
    ISS_MAP.sroll.current_tabindex = $$(this).index();
    //清除地图覆盖物
    ISS_MAP.ClearArc();
    //清空marker
    ISS_MAP.Markers = [];
    //查询
    if (ISS_MAP.sroll.current_tabindex == 0) {
        //重置页面序号
        ISS_MAP.sroll.index_tab0 = 1;
        //清除内容
        $$("#tab_Ticket .content-block").html("");
        $$('.infinite-scroll-preloaderTicket').show();
        //加载数据
        LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab0, ISS_MAP.sroll.current_tabindex);
    } else if (ISS_MAP.sroll.current_tabindex == 1) {
        //重置页面序号
        ISS_MAP.sroll.index_tab1 = 1;
        //清除内容
        $$("#tab_Hotel .content-block").html("");
        $$('.infinite-scroll-preloaderHotel').show();
        //加载数据
        LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab1, ISS_MAP.sroll.current_tabindex);
    } else if (ISS_MAP.sroll.current_tabindex == 2) {
        //重置页面序号
        ISS_MAP.sroll.index_tab2 = 1;
        //清除内容
        $$("#tab_Rest .content-block").html("");
        $$('.infinite-scroll-preloaderRest').show();
        //加载数据
        LoadAll(ISS_MAP.Keyword, ISS_MAP.sroll.index_tab2, ISS_MAP.sroll.current_tabindex);
    }
});

//点击列表定位
$$(".tab").on("click", ".mapcontent", function () {
    // debugger;
    //获取Index
    var index = parseInt($(this).attr("indexT"));
    //获取当前点位
    var localpoint = '';
    //定义图标
    var c_myIcon = "";
    //定义新的Marker集合
    var NewMarker = [];
    if (index) {
        localpoint = new BMap.Point(ISS_MAP.Markers[index - 1].point.lng, ISS_MAP.Markers[index - 1].point.lat);
        for (var i = 0; i < ISS_MAP.Markers.length; i++) {
            //获取位移
            var v_offset_y = i * 50;
            //获取点位
            var point = new BMap.Point(ISS_MAP.Markers[i].point.lng, ISS_MAP.Markers[i].point.lat);
            //定义图标
            if (ISS_MAP.sroll.current_tabindex == 0) {
                if (i + 1 == index) {
                    c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
                        offset: new BMap.Size(25, 29),
                        imageOffset: new BMap.Size(0, 0 - v_offset_y)
                    });
                } else {
                    c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
                        offset: new BMap.Size(25, 29),
                        imageOffset: new BMap.Size(-30, 0 - v_offset_y)
                    });
                }
            } else if (ISS_MAP.sroll.current_tabindex == 1) {
                if (i + 1 == index) {
                    c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
                        offset: new BMap.Size(25, 29),
                        imageOffset: new BMap.Size(-60, 0 - v_offset_y)
                    });
                } else {
                    c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
                        offset: new BMap.Size(25, 29),
                        imageOffset: new BMap.Size(-90, 0 - v_offset_y)
                    });
                }
            } else if (ISS_MAP.sroll.current_tabindex == 2) {
                if (i + 1 == index) {
                    c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
                        offset: new BMap.Size(25, 29),
                        imageOffset: new BMap.Size(-120, 0 - v_offset_y)
                    });
                } else {
                    c_myIcon = new BMap.Icon("/Common/website/assets/images/common/map/Base/ico-map.png", new BMap.Size(25, 42), {
                        offset: new BMap.Size(25, 29),
                        imageOffset: new BMap.Size(-150, 0 - v_offset_y)
                    });
                }
            }
            //定义新的图标
            var newmarker = new BMap.Marker(point, { icon: c_myIcon }); // 创建点
            NewMarker[i] = newmarker; //添加到临时到集合
        }
        //移除所有旧图标
        for (var i = 0; i < ISS_MAP.Markers.length; i++) {
            ISS_MAP.nearByMap.removeOverlay(ISS_MAP.Markers[i]);
        }
        //展示所有新图标
        for (var i = 0; i < ISS_MAP.Markers.length; i++) {
            ISS_MAP.Markers[i] = NewMarker[i];
            ISS_MAP.nearByMap.addOverlay(ISS_MAP.Markers[i]);
        }
        //如果是当前点击的，设置top
        ISS_MAP.Markers[index - 1].setTop(true);
        //定位地图
        ISS_MAP.nearByMap.centerAndZoom(localpoint, 15);


        ISS_MAP_SEARCH_END_NAV.Lat = localpoint.lat;
        ISS_MAP_SEARCH_END_NAV.Lng = localpoint.lng;
        
    }
});

//新县临时点位数据
//1.公厕
$("#constElementDiv_Toilet").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Toilet(), "Toilet");
    ElementClick();
});
//2.自行车
$("#constElementDiv_Bike").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Bike(), "Bike");
    ElementClick();
});
//3.停车场
$("#constElementDiv_Park").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Park(), "Park");
    ElementClick();
});
//4.医院
$("#constElementDiv_Hospital").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Hospital(), "Hospital");
    ElementClick();
});
//5.长途汽车站
$("#constElementDiv_PassengerStation").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.PassengerStation(), "PassengerStation");
    ElementClick();
});
//6.物流快递
$("#constElementDiv_Logistics").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Logistics(), "Logistics");
    ElementClick();
});
//7.汽修厂
$("#constElementDiv_AutoMobile").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.AutoMobile(), "AutoMobile");
    ElementClick();
});
//8.体育馆游乐园
$("#constElementDiv_Gymnasium").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Gymnasium(), "Gymnasium");
    ElementClick();
});
//9.烧烤夜市
$("#constElementDiv_Barbucue").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Barbucue(), "Barbucue");
    ElementClick();
});
//10.商场
$("#constElementDiv_Market").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Market(), "Market");
    ElementClick();
});
//11.景点
$("#constElementDiv_Attrac").click(function () {
    ISS_MAP.ClearArc();
    ISS_MAP.DrawArcConst(ISS_Map_BaseElement_XX.Attrac(), "Attrac");
    ElementClick();
});

//显示隐藏
var isShow = false;
$("#constShow").click(function () {
    if (!isShow) {
        $("#constElementDivParent").show();
        $("#constShow a.up").show();
        $("#pickbar")[0].style.height = "20px";
        $("#map-box")[0].style.height = "calc(100% - 20px)";
        pickheight = false;
        isShow = true;
    } else {
        $("#constElementDivParent").hide();
        $("#constShow a.up").hide();
        $("#pickbar")[0].style.height = "42%";
        $("#map-box")[0].style.height = "58%";
        pickheight = true;
        isShow = false;
    }
});

//显示隐藏
var isShow = false;
$("#constShow_ysp").click(function () {
    if (!isShow) {
        $("#constElementDivParent").show();
        $("#constShow_ysp a.up").show();
        // $("#map-box")[0].style.height = "calc(100% - 20px)";
        pickheight = false;
        isShow = true;
    } else {
        $("#constElementDivParent").hide();
        $("#constShow_ysp a.up").hide();
        // $("#map-box")[0].style.height = "58%";
        pickheight = true;
        isShow = false;
    }
});

function ElementClick_ysp() {
    if (!isShow) {
        $("#constElementDivParent").show();
        $("#constShow_ysp a.up").show();
        isShow = true;
    } else {
        $("#constElementDivParent").hide();
        $("#constShow_ysp a.up").hide();
        isShow = false;
    }
};

function ElementClick() {
    if (!isShow) {
        $("#constElementDivParent").show();
        $("#constShow a.up").show();
        isShow = true;
    } else {
        $("#constElementDivParent").hide();
        $("#constShow a.up").hide();
        isShow = false;
    }
};

console.log("length: " + $('.floating-button').length);
function onNavigationMapTap(){

    $('.floating-button1').each(function(index, e){
    $(this).click(function () {
       
        event.stopPropagation();
       
         ISS_MAP_SEARCH_END_NAV.Lng = ISS_MAP.Markers[index].point.lng;
         ISS_MAP_SEARCH_END_NAV.Lat = ISS_MAP.Markers[index].point.lat;
        var jsonstr1 = JSON.stringify(ISS_MAP_SEARCH_START_NAV);
        var jsonstr2 = JSON.stringify(ISS_MAP_SEARCH_END_NAV);
        // encodeURIComponent()转码
         window.location.href = '../map/navigationMap.html?map_start='+encodeURIComponent(JSON.stringify(ISS_MAP_SEARCH_START_NAV))+'&map_end='+encodeURIComponent(JSON.stringify(ISS_MAP_SEARCH_END_NAV));
        // window.open();
    })
});
    $('.floating-button2').each(function(index, e){
    $(this).click(function () {
       
        event.stopPropagation();
       
         ISS_MAP_SEARCH_END_NAV.Lng = ISS_MAP.Markers[index].point.lng;
         ISS_MAP_SEARCH_END_NAV.Lat = ISS_MAP.Markers[index].point.lat;
        var jsonstr1 = JSON.stringify(ISS_MAP_SEARCH_START_NAV);
        var jsonstr2 = JSON.stringify(ISS_MAP_SEARCH_END_NAV);
        // encodeURIComponent()转码
         window.location.href = '../map/navigationMap.html?map_start='+encodeURIComponent(JSON.stringify(ISS_MAP_SEARCH_START_NAV))+'&map_end='+encodeURIComponent(JSON.stringify(ISS_MAP_SEARCH_END_NAV));
        // window.open();
    })
});

    $('.floating-button3').each(function(index, e){
    $(this).click(function () {
       
        event.stopPropagation();
       
         ISS_MAP_SEARCH_END_NAV.Lng = ISS_MAP.Markers[index].point.lng;
         ISS_MAP_SEARCH_END_NAV.Lat = ISS_MAP.Markers[index].point.lat;
        var jsonstr1 = JSON.stringify(ISS_MAP_SEARCH_START_NAV);
        var jsonstr2 = JSON.stringify(ISS_MAP_SEARCH_END_NAV);
        // encodeURIComponent()转码
         window.location.href = '../map/navigationMap.html?map_start='+encodeURIComponent(JSON.stringify(ISS_MAP_SEARCH_START_NAV))+'&map_end='+encodeURIComponent(JSON.stringify(ISS_MAP_SEARCH_END_NAV));
        // window.open();
    })
});

}
